<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>个人资料</title>
    <meta name="keywords" content="基层e生">
    <meta name="description" content="基层e生">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="../../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../../css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="../../css/animate.css" rel="stylesheet">
    <link href="../../css/plugins/ztree/style.css?v=4.1.0" rel="stylesheet">

</head>
<body class="form-horizontal">
 <div class="wrapper wrapper-content animated fadeInRight"> 
   <div class="col-sm-6" style="margin-top: 50px;margin-left: 50px ; " > 
	    <div class="form-group">
	        <label for="userName" class="col-sm-3 control-label">姓名</label>
	        <div class="col-sm-8">
	          <input type="text" class="form-control" data-bind='value:agentName' id="agentName" placeholder="请输入真实姓名">
	        </div>
		</div>
	     <!-- <div class="input-group form-group">
	        <label for="password" class="col-sm-3 control-label">密码</label> 
	          <div class="col-sm-8"> 
					<div id="toolbar" class="form-inline">
				<input type="password" class="form-control input-sm" data-bind='value:pwd' id="pwd" placeholder="密码"  / >
				<button id="btn_search" type="button" class="btn btn-primary">	搜索</button> 
				<span class="req" style=" display: inline-block;margin-top: 6px;color: red;font-size: 20px;">*
					<label	 class="col-sm-3 control-label"></label><button  type="button" class="btn btn-default" onclick="operate.updatePwd('aa')" >修改密码</button></label></span>  
			 </div>
		</div>  
		<div class="col-sm-8">
		<input type="text" class="form-control" placeholder="Search for...">
		<span class="input-group-btn">
		  <button class="btn btn-default" type="button">Go!</button>
		</span>
	</div>
	</div> -->

	<!-- <div class="input-group">
			<label for="password" class="col-sm-3 control-label">密码</label>
			 <div class="col-sm-8">
			<input type="text" class="form-control" placeholder="Search for..."  >
			<span class="input-group-btn">
			  <button class="btn btn-default" type="button">Go!</button>
			</span>
		 </div>
		  </div> -->


		  
    <div class="form-group">
	        <label for="idCard" class="col-sm-3 control-label">身份证号码</label>
	        <div class="col-sm-8">
	            <input type="text" class="form-control" data-bind='value: idNum' id="idNum"  placeholder="输入身份证号码">
	        </div>
	    </div>
		<div class="form-group">
	        <label for="userName" class="col-sm-3 control-label">账户余额</label>
	        <div class="col-sm-8">
	          <input type="text" class="form-control" data-bind='value:amount' id="amount" readonly="value">
	        </div>
	    </div>
	    <div class="form-group">
            <button id="update" class="btn" style="margin-left: 50%;margin-top: 30px"onclick="operate.updateInfo()">修改信息</button>
        </div>
	
</div>
</div> 
</body>
<!-- 全局js -->
<script src="../../js/jquery.min.js?v=2.1.4"></script>
<script src="../../js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="../../js/content.js?v=1.0.0"></script>
<!--MVVM框架-->
<script type="text/javascript" src="../../js/plugins/knockout/knockout-3.4.2.js"></script>
<script type="text/javascript" src="../../js/plugins/knockout/knockout.mapping-latest.js"></script>
<!-- Bootstrap table -->
<script src="../../js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="../../js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="../../js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="../../js/common/auth.js"></script>

<script type="text/javascript">
    var __changeDetail = "/appAgent/updateAgentInfo";//post
    var __getCurrent = "/agent/current" ;//获取当前用户
	var __listDeptUrl = "/dept/read/list";
	var maxHeight = top.document.body.clientHeight * 1 ; //文档高度的80%
    var newModel;
    // $(function(){
	// 	tableInit.Init();

	// 	//2、注册增删改事件
	// 	operate.operateInit();

		


    // 	$$ajax({
	//         url: __getCurrent,
	//         type: "get",
	//         contentType: 'application/json',
	//         success: function(response) {
	//             if (response.code == 200) {
	//                 console.log("查询成功");
	// 			response.data.newPwd="";
	// 				newModel = ko.mapping.fromJS(response.data);
	// 				ko.applyBindings(newModel,document.body);
	//             } else {
	//             	console.log(data.msg);
	//             }
	
	//             //tableInit.myViewModel.refresh();
	//         }
	// 	});
	// }

	$(function () {
        //1、初始化表格
      //  tableInit.Init();

        //2、注册增删改事件
     //   operate.operateInit();

        //3、日期初始化
	//	dateInit.Init();
		
		$$ajax({
	        url: __getCurrent,
	        type: "get",
	        contentType: 'application/json',
	        success: function(response) {
	            if (response.code == 200) {
					console.log("查询成功");
					response.data.amount =  response.data.amount/100;
					newModel = ko.mapping.fromJS(response.data);
					ko.applyBindings(newModel,document.body);

	            } else {
	            	console.log(data.msg);
	            }
	
	            //tableInit.myViewModel.refresh();
	        }
		});
	
    });

	var koModel={
        updatePwdModel:{
            id:ko.observable(),
		    oldPwd:ko.observable(),
            updatePwd1:ko.observable(),
            updatePwd2:ko.observable()
        },

		updateModel:{
            id:ko.observable(),
			memId:ko.observable(),
			oldPwd:ko.observable(),
            updatePwd1:ko.observable(),
            updatePwd2:ko.observable(),
			agentName:ko.observable(),
			idNum:ko.observable(),
			amount:ko.observable()
        }
    };
	var operate = {
        //初始化按钮事件
        operateInit: function () {
            //this.operateAdd();
            //this.operateUpdate();
            //this.operateDelete();
            this.updatePwd();
			this.updateInfo();
        },
	
        //修改用户密码
        updatePwd:function(id){
			var newModel =  $.extend(true,{},koModel.updatePwdModel);
		    newModel.id(id);
            top.layer.open({
                title:"修改用户密码",
                type: 1,
                area: "500px",
                maxHeight:maxHeight,
				content:$get("/html/sys_base_user/updatePwd.html"),
             	 btn: ["保存", "取消"],
                yes: function(index, layerDom){
                	var close = top.layer.load(1);
                    var jsModle = ko.mapping.toJS(newModel);
                    var pass = "^[A-Za-z0-9]{1,}$";
                    if(!jsModle.updatePwd1||!jsModle.updatePwd2){
                    	top.layer.close(close);
                        top.layer.alert('密码不能为空或空格!', {icon: 6});
                        return;
                    }
                    if(!jsModle.updatePwd1.match(pass)){
                    	top.layer.close(close);
                        top.layer.alert('密码只能是数字与字母组成!', {icon: 6});
                        return;
                    }
                    if(jsModle.updatePwd1 != jsModle.updatePwd2){
                    	top.layer.close(close);
                        top.layer.alert('密码不一致，请输入正确密码!', {icon: 6});
                        return;
                    }
                    var dataUpdate={id:jsModle.id,memPassword:jsModle.updatePwd1};
				    $$ajax({
                        url: __addOrUpdateUrl,
                        type: 'post',//提交的方式
                        dataType:'json',
                        contentType:"application/json; charset=utf-8",
                        data:JSON.stringify(dataUpdate),
                        success: function(data) {
                            if (data.httpCode==200) {
                            	top.layer.close(close);
                                top.layer.alert("更新成功");
                                top.layer.close(index);
                            } else{
                            	top.layer.close(close);
                                alert(data.msg);
                            }
                        }
                    });
                },
                btn2:function(index,layarDom){//关闭
                    ko.cleanNode(layarDom.get(0));
                },
                success:function(layarDom,index){//弹层加载成功
                    ko.applyBindings(newModel, layarDom.get(0));
                    //var unmapped = ko.mapping.toJS(operate.entityModel);
                }
            });
        },

		updateInfo:function(){
			var aaaa =  newModel.idNum()
			var jsModle = ko.mapping.toJS(newModel);
			var dataUpdate={memId:jsModle.id,idNum:jsModle.idNum,agentName:jsModle.agentName};
				    $$ajax({
                        url: __changeDetail,
                        type: 'post',//提交的方式
                        dataType:'json',
                        contentType:"application/json; charset=utf-8",
						//data:dataUpdate,
						 data:JSON.stringify(dataUpdate),
                        success: function(data) {
                            if (data.code==200) {
                            	alert("更新成功")
                            } else{
								alert("更新失败")
								
                                alert(data.msg);
                            }
                        }
                    });
        }
	}
</script>

</html>